package bishiqiangxun;
import java.io.*;
public class Test2 {
    //题目 : 笔试强训day38第二题 dd爱旋转
    //要IO输 入
    public static void main (String[] args) throws IOException{
        //Scanner in = new Scanner(System.in);
        BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter write = new BufferedWriter(new OutputStreamWriter(System.out)); //写
        //正常输入会超时  要用IO输入
        // 注意 hasNext 和 hasNextLine 的区别
        int n = Integer.parseInt(read.readLine());
        int[][] arr = new int[n][n];
        for(int i = 0; i < n; i++) {
            String[] s = read.readLine().split(" ");
            for(int j = 0; j < n; j++) {
                arr[i][j] = Integer.parseInt(s[j]);
            }
        }

        int q = Integer.parseInt(read.readLine());
        int one = 0;
        int two = 0;
        for(int i = 0; i< q;i++) {
            int x = Integer.parseInt(read.readLine());
            if(x == 1) {
                one++;
            }
            if(x == 2) {
                two++;
            }
        }

        if(one % 2 == 0) {
            if(two % 2 == 0) {
                //都是偶数相当于没旋转
                for(int i = 0; i < n; i++) {
                    for(int j = 0; j< n; j++) {
                        write.write(arr[i][j] + " ");
                    }
                    //换行
                    //System.out.println();
                    write.newLine();
                }
            }else{
                //2是奇数
                //发生行镜像
                for(int i = 0;i < n; i++) {
                    for(int j = 0; j< n; j++) {
                        write.write(arr[n-i-1][j] + " ");
                    }
                    //System.out.println();
                    write.newLine();
                }
            }
        }else {if(two % 2 == 0){
            //操作1是奇数  2是偶数
            for(int i = 0;i < n; i++) {
                for(int j = 0; j< n; j++) {
                    write.write(arr[n-i-1][n-j-1] + " ");
                }
                write.newLine();
            }
        }else {
            //全为奇数
            for(int i = 0;i < n; i++) {
                for(int j = 0; j< n; j++) {
                    write.write(arr[i][n-j-1] + " ");
                }
                write.newLine();
            }
        }
        }
        //关闭一下资源
        read.close();
        write.close();
    }
}
